import { post } from "@/util/request";
import { goReLaunch } from "@/static/ts/common";
import { SysTime } from "@/api/SystemApi";
import i18n from "@/i18n";
// import { initializeWebSocket, disconnectWebSocket } from "@/util/websocket";

// 用户登录
export const Logon = async (data: any) => {
	uni.showLoading({
		mask: true
	})
	const obj = await post("/UserApi/Logon", data);
	await getUserInfo(obj);
};
// 发送注册验证码
export const SendRegisterVerificationCode = async (data: any) => {
	await post("/UserApi/SendRegisterVerificationCode", data);
};
// 注冊
export const UserRegister = async (data: any) => {
	uni.showLoading({
		mask: true
	})
	const obj = await post("/UserApi/UserRegister", data);
	getUserInfo(obj);
};
// 获取用户信息并且跳转
export const getUserInfo = async (obj: any) => {
	uni.setStorageSync("userInfo", obj);
	await UserInfo();
	await SysTime();
	uni.hideLoading()
	goReLaunch("/pages/index/index",  i18n.global.t('common.loginSuccess'));
};

// 用戶信息
export const UserInfo = async () => {
	let obj = await post("/UserApi/UserInfo");
	if (uni.getStorageSync("userInfo")) {
		obj = {
			...uni.getStorageSync("userInfo"),
			...obj,
		};
	}
	uni.setStorageSync("userInfo", obj);
	return obj;
};
// 修改资料
export const UserInfoUpdate = async (data: any) => {
	 await post("/UserApi/UserInfoUpdate", data);
	uni.showToast({ title: i18n.global.t('common.updateSuccess'), icon: "none" });
	UserInfo();
};
// 退出登录
export const LogOut = async () => {
	await post("/UserApi/LogOut");
	goReLaunch("/pages/notLoggedIn/login",  i18n.global.t('common.logout'));
};

// 设置交易密码
export const PaymentPwSet = async (data: any) => {
	await post("/UserApi/PaymentPwSet", data);
};

// 修改交易密码
export const PaymentPwUpdate = async (data: any) => {
	await post("/UserApi/PaymentPwUpdate", data);
};
// 修改登录密码
export const PwUpdate = async (data: any) => {
	await post("/UserApi/PwUpdate", data);
};
// 用户余额
export const UserMoney = async () => {
	let obj = await post("/UserApi/UserMoney");
	uni.setStorageSync("UserMoney", obj);

	return obj;
};
// 用户报表
export const UserStatistics = async () => {
	let obj = await post("/UserApi/UserStatistics");
	uni.setStorageSync("UserStatistics", obj);

	return obj;
};

// 银行类型列表
export const BankCategory = async () => {
	let arr = await post("/UserApi/BankCategory");
	return arr;
};

// 用户提现银行卡添加
export const UserWithdrawalBankCardAdd = async (data: any) => {
	let obj = await post("/UserApi/UserWithdrawalBankCardAdd", data);
	return obj;
};
// 用户提现银行卡删除
export const UserWithdrawalBankCardDel = async (data: any) => {
	let obj = await post("/UserApi/UserWithdrawalBankCardDel", data);
	return obj;
};

// 用户提现银行卡列表
export const UserWithdrawalBankCard = async () => {
	let obj = await post("/UserApi/UserWithdrawalBankCard");
	return obj;
};
// 提现
export const UserWithdrawal = async (data: any) => {
	let obj = await post("/UserApi/UserWithdrawal", data);
	return obj;
};
// 网银支付通道列表 
export const UsdtChannel = async () => {
	let obj = await post("/UserApi/UsdtChannel");

	return obj;
};
// 充值通道地址
export const UsdtChannelAdress = async (data: any) => {
	let obj = await post("/UserApi/UsdtChannelAdress", data);

	return obj;
};

// 充值补单
export const HashRepair = async (data: any) => {
	uni.showLoading({
		mask: true
	})
	let obj = await post("/UserApi/HashRepair", data);
	uni.hideLoading()
	return obj;
};
// 快捷支付下单
export const QuickPaymentPlaceOrder = async (data: any) => {
	let obj = await post("/UserApi/QuickPaymentPlaceOrder", data);
	return obj;
};

// 提现记录
export const UserWithdrawalBankCardOrder = async (data: any) => {
	let obj = await post("/UserApi/UserWithdrawalBankCardOrder", data);
	return obj;
};

// 充值记录
export const UsersRechargeOrder = async (data: any) => {
	let obj = await post("/UserApi/UsersRechargeOrder", data);
	return obj;
};
// 利润账户账变类型
export const OrderType = async () => {
	let obj = await post("/UserApi/OrderType", {});
	return obj;
};
// 利润账户账变订单
export const UserOrder = async (data: any) => {
	let obj = await post("/UserApi/UserOrder", data);
	return obj;
};

// 量化账户账变类型
export const OrderTypeQuantify = async () => {
	let obj = await post("/UserApi/OrderTypeQuantify", {});
	return obj;
};
// 量化账户账变订单
export const UserOrderQuantify = async (data: any) => {
	let obj = await post("/UserApi/UserOrderQuantify", data);
	return obj;
};


// 智慧账户账变类型
export const OrderTypeWisdom = async () => {
	let obj = await post("/UserApi/OrderTypeWisdom", {});
	return obj;
};
// 智慧账户账变订单
export const UserOrderWisdom = async (data: any) => {
	let obj = await post("/UserApi/UserOrderWisdom", data);
	return obj;
};

// 转换类型列表
export const UserSwitchType = async () => {
	let obj = await post("/UserApi/UserSwitchType", {});
	return obj;
};
// 资金转换
export const UserFundSwitching = async (data: any) => {
	let obj = await post("/UserApi/UserFundSwitching", data);
	return obj;
};
// 用户消息列表
export const UsersMail = async (data: any) => {
	let obj = await post("/UserApi/UsersMail", data);
	return obj;
};

// 用户消息详情
export const UsersMailInfo = async (data: any) => {
	let obj = await post("/UserApi/UsersMailInfo", data);
	return obj;
};
// 用户消息详情
export const UsersMailUnreadCount = async () => {
	let obj = await post("/UserApi/UsersMailUnreadCount", {});
	return obj;
};
// 用户消息删除
export const UsersMailDelete = async (data: any) => {
	let obj = await post("/UserApi/UsersMailDelete", data);
	return obj;
};
// 团队统计
export const TeamStatistics = async () => {
	let obj = await post("/UserApi/TeamStatistics", {});
	return obj;
};
// 团队用户列表
export const TeamUser = async (data: any) => {
	let obj = await post("/UserApi/TeamUser", data);
	return obj;
};
// 返佣订单
export const TeamRebateOrder = async (data: any) => {
	let obj = await post("/UserApi/TeamRebateOrder", data);
	return obj;
};
